<div class="col-md-8">
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header products clearfix">
				<h1>Existing Bids</h1>
		</div>
		<div class="user-profile1 col-md-12">
		<form id="formid" method="post" class="form-horizontal" role="form">
		<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='superadmin') {?>
				<div class="form-group">
				<label class="control-label col-sm-3">Admins:</label>
				<div class="col-sm-9">
				<select id="admin" name="admin" onchange="changeCategory('admin')">
					<option value="">--Select admin--</option>
					<? if(count($this->getalladmin)>0){foreach($this->getalladmin as $admins){?>						
							<option value="<? echo $admins->user_id;?>"><? echo $admins->company_name;?></option>						
					<?}}?>
				</select>
				</div>
				</div>
			<?}?>
			<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin') {?>
				<input type="hidden" id="admin" name="admin" value="all">
			<? }?>
			<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']!='user') {?>
				<div class="form-group">
				<label class="control-label col-sm-3">Users:</label>
				<div class="col-sm-9">
				<select id="user" name="user" onchange="changeCategory('user')">
					<option value="">--Select user--</option>	
					<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin') {?>	
					<? if(count($this->getallusers)>0){foreach($this->getallusers as $users){?>						
							<option value="<? echo $users->user_id.'/'.$users->company_name;?>"><? echo $users->company_name;?></option>						
					<?}}}?>					
				</select>
				</div>
				</div>
			<?}?>
			<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='user') {?>
				<input type="hidden" id="admin" name="admin" value="all">
				<input type="hidden" id="user" name="user" value="all">
			<? }?>
			<div class="form-group">
				<label class="control-label col-sm-3">Country:</label>
				<div class="col-sm-9">
				<select id="Country" name="Country" onchange="changeCategory('country')">
					<option value="">--Select Country--</option>
					<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='user') {?>
					<? if(isset($this->getallcountries)){?>						
							<option value="<? echo $this->getallcountries;?>"><? echo $_SESSION['user']['countryname'];?></option>						
					<?}}?>
				</select>
				</div>
				</div>
				<div class="form-group">
				<label class="control-label col-sm-3">Industry:</label>
				<div class="col-sm-9">
				<select id="Industry" name="Industry" onchange="changeCategory('industry')">
					<option value="">--Select Industry--</option>					
				</select>
				</div>
				</div>
				<div class="form-group">
				<label class="control-label col-sm-3">Categories:</label>
				<div class="col-sm-9">
				<select id="category" name="category" onchange="changeCategory('category')">
					<option value="">--Select category--</option>					
				</select>
				</div>
				</div>
		
		<div class="product_table table-responsive">			
		</div>
		</form>
	</div>
</div> </div>    
<script>
function getUsers(){
	 var admin_user_id=$("#admin").val();
	 $.ajax({
		url:BASE_PATH+"/users/admin-users-ajax",
		type:"POST",
		data:{adminUserId:admin_user_id},
		success: function(data){
			if(data.output=='success'){
				$('#user').html(data.getadminUsers);
			}
		},
	});
}
function changeUserlist(){
	var user_id=$("#user").val();
	$.ajax({
		type:	'POST',
		url:   	BASE_PATH+'/products/get-user-regions',
		data:{user_id:user_id},
		success: function(data){
			if(data.output=='success'){
				$("#country").html(data.getallcountries);
				changeCategory('all');
			}else if(data.output=='not success'){
				$("#country").html(data.getallcountries);
				changeCategory('all');
			}
		}
	});
}
function changeCountry(){
	var country_id=$("#country").val();
	$.ajax({
		type:	'POST',
		url:   	BASE_PATH+'/products/get-industries',
		data:	{country_id:country_id},
		success: function(data){
			if(data.output=='success'){
				$("#industry").html(data.industries);
			}
		}
	});
}
function changeIndustry(industry_id){
	var country_id=$("#Country").val();
	$.ajax({
		type:	'POST',
		url:   	BASE_PATH+'/products/get-categories',
		data:	{country_id:country_id,industry_id:industry_id,check:'check'},
		success: function(data){
			if(data.output=='success'){
				$("#category").html(data.categories);
			}
		}
	});
}
$(function(){
	changeCategory('all');
});
function changeCategory(type){
$('.product_table').html('Please wait loading....');
	if(type=='all'){
		<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='superadmin') {?>
			var admin_id='all';
			var user_id='all';
		<?}else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin'){?>
			var admin_id='all';
			var user_id='all'
		<?}else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='user'){?>
			var admin_id='all';
			var user_id='all';
		<?}?>
		var cid='all';
		var inid='all';	
		var catid='all';
		$.ajax({
			type:	'POSt',
			dataType:'json',
			url:BASE_PATH+'/products/bid-sent-ajax',
			data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
			success: function(data){
			$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
			eval(data);
			var oTable = $('#search_results').dataTable( {
						aoColumnDefs: [{bSortable: false,
										aTargets: [ 0 ]
										}],
						"bStateSave": true,
						"bAutoWidth": true,
						"sRowSelect": "multi",
						"sPaginationType": "full_numbers",
						"bProcessing": true,
						"aaData": data,
						"aoColumns": [
							{ "mData": "sno" },
							{ "mData": "genericname" },
							{ "mData": "quntity" },
							{ "mData": "suggested_price" },
							{ "mData": "saleing" },
							{ "mData": "action" },
						] 
					});			
			}
		});
	}else if(type=='admin'){
		var cid='all';
		var inid='all';
		var catid='all';	
		if($("#admin").val()!=''){
			var admin_id=$("#admin").val();
		}else{
			var admin_id='all';
		}							
		$.ajax({
			type:	'POST',
			url:BASE_PATH+"/products/admin-users-ajax",
			data:	{adminUserId:admin_id},
			success: function(data){
				if(data.output=='success'){				
					$("#user").html(data.getadminUsers);					
					var user_id='all';
					$.ajax({
						type:	'POSt',
						dataType:'json',
						url:BASE_PATH+'/products/bid-sent-ajax',
						data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "genericname" },
									{ "mData": "quntity" },
									{ "mData": "suggested_price" },
									{ "mData": "saleing" },
									{ "mData": "action" },
								] 
							});			
						}
					});
				}
			}
		});
	}else if(type=='user'){		
		var inid='all';
		var catid='all';	
		if($("#admin").val()!=''){
			var admin_id=$("#admin").val();			
		}else{
			var admin_id='all';
		}
		if($("#user").val()!=''){
			var admin_id=$("#admin").val();
			var user_id=$("#user").val();
		}else{
			var user_id='all';
		}
		$.ajax({
		type:	'POST',
		url:   	BASE_PATH+'/products/get-user-regions',
		data:{user_id:user_id,check:'check'},		
			success: function(data){
				if(data.output=='success'){				
					$("#Country").html(data.getallcountries);
					var cid='all';
					$.ajax({
						type:	'POSt',
						dataType:'json',
						url:BASE_PATH+'/products/bid-sent-ajax',
						data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "genericname" },
									{ "mData": "quntity" },
									{ "mData": "suggested_price" },
									{ "mData": "saleing" },
									{ "mData": "action" },
								] 
							});			
						}
					});
				}
			}
		});
	}else if(type=='country'){
		if($("#Country").val()==''){
			var cid='all';
		}else{
			var cid=$("#Country").val();
		}		
		var inid='all';	
		if($("#admin").val()!=''){
			var admin_id=$("#admin").val();			
		}else{
			var admin_id='all';
		}
		if($("#user").val()!=''){
			var admin_id=$("#admin").val();
			var user_id=$("#user").val();
		}else{
			var user_id='all';
		}
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-industries',
			data:	{user_id:user_id,country_id:cid,industry_id:inid,check:'check'},
			success: function(data){
				if(data.output=='success'){				
					$("#Industry").html(data.industries);
					if($("#Country").val()==''){
						var inid='all';
						changeIndustry(inid);
					}else{
						var inid='all';
						changeIndustry(inid);
					}					
					var catid='all';
					$.ajax({
						type:	'POSt',
						dataType:'json',
						url:BASE_PATH+'/products/bid-sent-ajax',
						data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "genericname" },
									{ "mData": "quntity" },
									{ "mData": "suggested_price" },
									{ "mData": "saleing" },
									{ "mData": "action" },
								] 
							});			
						}
					});
				}
			}
		});
	}else if(type=='industry'){
		if($("#admin").val()!=''){
			var admin_id=$("#admin").val();			
		}else{
			var admin_id='all';
		}
		if($("#user").val()!=''){
			var admin_id=$("#admin").val();
			var user_id=$("#user").val();
		}else{
			var user_id='all';
		}
		if($("#Country").val()==''){
			var cid='all';
		}else{
			var cid=$("#Country").val();
		}
		if($("#Industry").val()==''){
			var inid='all';
		}else{
			var inid=$("#Industry").val();
		}			
		var check='check';		
		$.ajax({
			type:	'POST',
			url:   	BASE_PATH+'/products/get-categories',
			data:	{country_id:cid,industry_id:inid,check:'check'},			
			success: function(data){
				if(data.output=='success'){
					$("#category").html(data.categories);
					var catid=$("#category").val();
					$.ajax({
						type:	'POSt',
						dataType:'json',
						url:BASE_PATH+'/products/bid-sent-ajax',
						data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
						success: function(data){
						$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
						eval(data);
						var oTable = $('#search_results').dataTable( {
								aoColumnDefs: [{bSortable: false,
												aTargets: [ 0 ]
												}],
								"bStateSave": true,
								"bAutoWidth": true,
								"sRowSelect": "multi",
								"sPaginationType": "full_numbers",
								"bProcessing": true,
								"aaData": data,
								"aoColumns": [
									{ "mData": "sno" },
									{ "mData": "genericname" },
									{ "mData": "quntity" },
									{ "mData": "suggested_price" },
									{ "mData": "saleing" },
									{ "mData": "action" },
								] 
							});			
						}
					});
				}
			}
		});
	}else if(type=='category'){
		var cid=$("#Country").val();
		var inid=$("#Industry").val();
		var catid=$("#category").val();	
		var admin_id=$("#admin").val();	
		var user_id=$("#user").val();
		$.ajax({
			type:	'POSt',
			dataType:'json',
			url:BASE_PATH+'/products/bid-sent-ajax',
			data:{admin_id:admin_id,user_id:user_id,country_id:cid,industry_id:inid,category_id:catid},
			success: function(data){
			$('.product_table').html('<table class="table table-bordered" cellpadding="0" cellspacing="0" width="100%" id="search_results"><thead><tr class="bg_header"><td>SNO</td><td>Product Name</td><td width="77px;">Quantity&nbsp;</td><td>Actual Price</td><td>Type</td><td>Action</td></tr></thead><tbody></tbody></table>');	
			eval(data);
			var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
					"aaData": data,
					"aoColumns": [
						{ "mData": "sno" },
						{ "mData": "genericname" },
						{ "mData": "quntity" },
						{ "mData": "suggested_price" },
						{ "mData": "saleing" },
						{ "mData": "action" },
					] 
				});			
			}
		});
	}
			
}
</script>